package com.free.semantic.core.impl.demo;

import com.free.semantic.common.Ls;
import com.free.semantic.common.RelationChain;
import com.free.semantic.core.ConceptManage;
import com.free.semantic.core.impl.BaseTest;
import com.free.semantic.core.impl.ConceptManageImpl;
import com.free.semantic.req.RelationDefineGroup;
import com.free.semantic.utils.Utils;
import org.junit.jupiter.api.Test;

import java.util.List;

public class Demo7_supportAutoVersion extends BaseTest {


    /**
     * 分支路径
     */
    @Test
    public void test() {
        {
            RelationDefineGroup group = new RelationDefineGroup();

            defineRelation(group, "属性", defineItem(oneObj("A"), oneObj("B"))); //A->B=[0,) //代表 针对任意一个A，都可以找到 [0,)个B与之对应

            ConceptManageImpl concept = (ConceptManageImpl) getConceptManage(group);

            concept.addConcept("支付单", "金额", "数字", "创建时间");

            Utils.createRelation(concept, "属性", "支付单", "金额");
            Utils.createRelation(concept, "属性", "支付单", "创建时间");

            Utils.createRelation(concept, "属性", "金额", "数字");
            Utils.createRelation(concept, "属性", "创建时间", "数字");

            List<RelationChain> relationChains = concept.findAllRelationChain(Ls.of("支付单"), "数字");
            System.out.println("test" + relationChains);
            assert relationChains.size() == 2;
        }
    }

    /**
     * 分支路径2
     */
    @Test
    public void test1() {
        {
            RelationDefineGroup group = new RelationDefineGroup();

            defineRelation(group, "属性", defineItem(oneObj("A"), oneObj("B"))); //A->B=[0,) //代表 针对任意一个A，都可以找到 [0,)个B与之对应

            ConceptManageImpl concept = (ConceptManageImpl) getConceptManage(group);

            concept.addConcept("支付单", "金额", "数字", "创建时间");

            Utils.createRelation(concept, "属性", "支付单", "金额");
            Utils.createRelation(concept, "属性", "支付单", "数字");

            Utils.createRelation(concept, "属性", "金额", "数字");

            List<RelationChain> relationChains = concept.findAllRelationChain(Ls.of("支付单"), "数字");
            System.out.println("test" + relationChains);
            assert relationChains.size() == 2;
        }
    }

    /**
     * 多来源事物的非分主路径
     */
    @Test
    public void test2() {
        {
            RelationDefineGroup group = new RelationDefineGroup();

            defineRelation(group, "属性", defineItem(oneObj("A"), oneObj("B"))); //A->B=[0,) //代表 针对任意一个A，都可以找到 [0,)个B与之对应

            defineRelation(group, "二元找到", defineItem(oneObj("A", "B"), oneObj("C"))); //A->B=[0,) //代表 针对任意一个A，都可以找到 [0,)个B与之对应

            ConceptManage concept = getConceptManage(group);

            concept.addConcept("支付单", "金额", "创建时间", "神奇的东西");
            Utils.createRelation(concept, "属性", "支付单", "金额");
            Utils.createRelation(concept, "属性", "支付单", "创建时间");
            Utils.createRelation2(concept, "二元找到", "金额", "创建时间", "神奇的东西");

            List<RelationChain> relationChains = concept.findAllRelationChain(Ls.of("支付单"), "神奇的东西");
            assert relationChains.size() == 1;
        }
    }

    /**
     * 多来源事物的非分主路径
     */
    @Test
    public void test3() {
        {
            RelationDefineGroup group = new RelationDefineGroup();
            defineRelation(group, "属性", defineItem(oneObj("A"), oneObj("B"))); //A->B=[0,) //代表 针对任意一个A，都可以找到 [0,)个B与之对应
            ConceptManageImpl concept = (ConceptManageImpl) getConceptManage(group);

            concept.addConcept("支付单", "金额", "数字", "创建时间");
            Utils.createRelation(concept, "属性", "支付单", "金额");
            Utils.createRelation(concept, "属性", "金额", "数字");

            int currentVersion = concept.getLastVersion();

            concept.increaseVersion();
            Utils.createRelation(concept, "属性", "支付单", "创建时间");
            Utils.createRelation(concept, "属性", "创建时间", "数字");
            List<RelationChain> relationChains = concept.findAllRelationChain(currentVersion, Ls.of("支付单"), "数字");

            assert relationChains.size() == 1;
        }
    }


}
